package main

import (
	"backend/config"
	"backend/log"
	"backend/utils"
	"fmt"

	"backend/middlewares"
	"backend/routers"

	"github.com/gin-gonic/gin"
)

func main() {
	config.Init()
	log.LogInit(config.CF.Logging)
	utils.InitDB(config.CF.Mysql)
	utils.InitRedis(config.CF.Redis)

	r := gin.Default()
	r.Use(middlewares.Cors())
	r.Use(middlewares.ZapLoggerMiddleware(log.Logger))
	r.Use(middlewares.JWTAuthMiddleware())
	r.Use(middlewares.Permission(utils.DB))
	routers.RegisterUserRoutes(&r.RouterGroup)
	routers.RegisterMenuRoutes(&r.RouterGroup)
	routers.RegisterPerminssionRoutes(&r.RouterGroup)
	routers.RegisterRoleRoutes(&r.RouterGroup)
	routers.RegisterGroupRoutes(&r.RouterGroup)
	r.Run(fmt.Sprintf("%s:%d", config.CF.Listener.Host, config.CF.Listener.Port))
}
